package com.jpcc.vw.onlineRadio.activity;

import android.content.Intent;
import android.os.RemoteException;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.cns.android.hmi.HMIManager;
import com.jpcc.vw.onlineRadio.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SourceActivity extends com.jpcc.vw.onlineRadio.base.BaseActivity {

    @BindView(R.id.tv_title)
    TextView tv_title;


    @Override
    public int getLayoutId() {
        return R.layout.fragment_sources;
    }

    @Override
    public void setupView() {
        ButterKnife.bind(this);
        tv_title.setText(getResources().getString(R.string.string_0));
    }

    @OnClick({R.id.layout_back, R.id.layout_db,R.id.layout_online_media,R.id.layout_cd,R.id.layout_database,R.id.layout_bt,R.id.layout_online_radio})
    void doClicks(View view) {
        int id = view.getId();
        switch (id) {
            case R.id.layout_back:
                this.finish();
                break;
            case R.id.layout_db:
                try {
                    HMIManager.getInstance(this).switchToLinux(HMIManager.ENTRY_POINT_TUNER_FM_MAIN);
                } catch (RemoteException e) {
                    e.printStackTrace();
                }
                break;
            case R.id.layout_cd:
                try {
                    HMIManager.getInstance(this).switchToLinux(HMIManager.ENTRY_POINT_TUNER_AM_MAIN);
                } catch (RemoteException e) {
                    e.printStackTrace();
                }
                break;
            case R.id.layout_database:
                try {
                    HMIManager.getInstance(this).switchToLinux(HMIManager.ENTRY_POINT_MEDIA_JUKEBOX_MAIN);
                } catch (RemoteException e) {
                    e.printStackTrace();
                }
                break;
            case R.id.layout_bt:
                try {
                    HMIManager.getInstance(this).switchToLinux(HMIManager.ENTRY_POINT_MEDIA_BT_MAIN);
                } catch (RemoteException e) {
                    e.printStackTrace();
                }
                break;
            case R.id.layout_online_media:
//                Intent intent=new Intent(Intent.ACTION_MAIN);
//                ComponentName componentName = new ComponentName("com.jpcc.vw.music","com.jpcc.vw.music.ui.LoadingActivity");
//                intent.setComponent(componentName);
//                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//                startActivity(intent);
                try
                {
                    Intent intent=this.getPackageManager().getLaunchIntentForPackage("com.jpcc.vw.music");
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                }
                catch (Exception e){
                    Toast.makeText(this,"Media not installed",Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.layout_online_radio:
                SourceActivity.this.finish();
                break;
        }
    }
}
